﻿using Quartz.Api.Model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quartz.Api.Helper
{
    public class SugarContext
    {
        public SugarContext()
        {
            var path = Directory.GetCurrentDirectory();
            //获取sqlite连接字符串
            var dbname = Appsettings.app("DbConnection");

            var Conn = ($"Data Source = {path}\\{dbname}").ReplacePath();

            Db = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = Conn,
                DbType = DbType.Sqlite,
                InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息
                IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样我就不多解释了
            });
        }

        //注意：不能写成静态的
        public SqlSugarClient Db;//用来处理事务多表查询和复杂的操作


        public SimpleClient<AccessLog> AccessLogDb { get { return new SimpleClient<AccessLog>(Db); } }
    }
}
